

$(document).bind('keydown', 'Ctrl+B', function(){alert('key')});


function HandyPreference(site,filename,title,description){
	this.site=site;
	this.filename=filename;
	this.title=title;
	this.description=description;
}

var HandyPrefs = new Array();

HandyPrefs.push(new HandyPreference("GMail","gmail-userbar","Hide user bar","Hides the topmost bar that contains navigation to other services and settings link."))
HandyPrefs.push(new HandyPreference("GMail","gmail-logosearch","Hide logo and search box","Hides the bar that contains Google's logo and the search box."))
HandyPrefs.push(new HandyPreference("GMail","gmail-leftcol","Hide left column","Hides the left column of the page that contains links to Compose Mail, Inbox and Labels"))
HandyPrefs.push(new HandyPreference("GMail","gmail-chat","Hide chat widget","Removes the chat box from the page. Be sure to set your status to offline before you use this tweak."))

HandyPrefs.push(new HandyPreference("Google Docs","docs-userbar","Hide user bar","Hides the topmost bar that contains navigation to other services and Docs settings link."))
HandyPrefs.push(new HandyPreference("Google Docs","docs-logosearch","Hide Google logo and search box","Hides the bar that contains Google's logo and the search box."))

HandyPrefs.push(new HandyPreference("iGoogle","igoogle-userbar","Hide user bar","Hides the topmost bar that contains navigation to other services and iGoogle settings link."))
HandyPrefs.push(new HandyPreference("iGoogle","igoogle-logosearch","Hide logo and search box","Hides the bar that contains Google's logo and the search box."))
HandyPrefs.push(new HandyPreference("iGoogle","igoogle-leftbar","Hide left column","Hides the left column of the page that contains links to iGoogle tabs."))
HandyPrefs.push(new HandyPreference("iGoogle","igoogle-roundedborders","Remove round borders","Remove the rounded corners of widgets and their move/settings icons."))
HandyPrefs.push(new HandyPreference("iGoogle","igoogle-footer","Hide footer","Hides page footer."))

HandyPrefs.push(new HandyPreference("Google Reader","reader-userbar","Hide user bar","Hides the topmost bar that contains navigation to other services and Reader settings link."))
HandyPrefs.push(new HandyPreference("Google Reader","reader-logosearch","Hide logo and search box","Hides the bar that contains Google's logo and the search box."))
HandyPrefs.push(new HandyPreference("Google Reader","reader-smallerfont","Smaller font for post list","Reduces font-size for items on the list of posts."))

for(i=0;i<HandyPrefs.length;i++){
	if(!localStorage[HandyPrefs[i].filename]){
		localStorage[HandyPrefs[i].filename] = 0;
	}
}





function loadCss(node,cssid,path){
	path = chrome.extension.getURL(path)
	$(node).append('<link id="'+cssid+'" rel="stylesheet" type="text/css" href="'+path+'">');
}


function loadInterface(nodeHead,nodeBody,site){

	chrome.extension.onRequest.addListener(
			function(request, sender, sendResponse) {
				if(request.doaction == "showOptions"){
					$("div#dialog-overlay").show()
					$('#dialog-handyman').show(); 
					sendResponse({}); 
				}
			}
	);
	chrome.extension.sendRequest({doaction: "showIcon"}, function(response) {});
	
	var cssPath = chrome.extension.getURL('sites/'+site+'/')
	var handyPath = chrome.extension.getURL('handyman/')
	
	var maskWidth = $(window).width();
	var maskHeight = $(document).height(); 
	
	$(nodeBody).prepend('<div id="morelink"></div>')
	$(nodeBody).prepend('<div id="dialog-overlay"></div>')
	$('div#dialog-overlay').css({height:maskHeight}).hide()
	$(nodeBody).prepend('<div id="dialog-handyman"></div>')    
	$('div#dialog-handyman').css({top:"50px", left:((maskWidth/2) - 200)}).hide()
	
	
	$("div#dialog-handyman").append('<div id="dialog-title">Settings for: '+site+'</div>')
	
	//loads site preferences
	for(i=0;i<HandyPrefs.length;i++){
		if(HandyPrefs[i].site == site){
			$(nodeHead).append('<link id="handycss_'+HandyPrefs[i].filename+'" rel="stylesheet" type="text/css">');
			if(localStorage[HandyPrefs[i].filename] == 1){
				thisState = "active"
				$("link#handycss_"+HandyPrefs[i].filename).attr("href",cssPath+HandyPrefs[i].filename+".css")
			} else {
				thisState = "inactive"
				$("link#handycss_"+HandyPrefs[i].filename).attr("href",handyPath+"empty.css")
			}
			
			eachHandyStr = '<div class="eachHandy">'
			eachHandyStr += 	'<div class="optionDescription">'
			eachHandyStr += 		'<span class="prefTitle">'+HandyPrefs[i].title+'</span>'
			eachHandyStr += 			'<br>'
			eachHandyStr += 		'<span class="prefDescription">'+HandyPrefs[i].description+'</span>'
			eachHandyStr +=		'</div>'
			eachHandyStr += 	'<div class="optionCheckbox">'
			eachHandyStr += 		'<a href="#" class="toggleOption" state="'+thisState+'" item="'+HandyPrefs[i].filename+'" id="togglelink_'+HandyPrefs[i].filename+'">'
			eachHandyStr +=				'<img src="'+handyPath+'img/'+thisState+'.png" id="img_'+HandyPrefs[i].filename+'">'
			eachHandyStr +=			'</a>'
			eachHandyStr += 	'</div>'
			eachHandyStr += 	'<div style="clear:both"></div>'
			eachHandyStr += '</div>'
			
			$("div#dialog-handyman").append(eachHandyStr)
			$("#togglelink_"+HandyPrefs[i].filename).addClass(thisState)
		}
	}
	$("div#dialog-handyman").append('<div class="actions"><div class="btncontainer"><a href="#" class="savePrefs">SAVE SETTINGS</a></div></div>')
	
	$(".savePrefs").bind('click',function(){
			$("div#dialog-overlay").hide()
			$("div#dialog-handyman").hide()
			return false;
	})
	
	$(".toggleOption").bind('click',function(){
		if($(this).attr("state") == "inactive"){
			$(this).removeClass("inactive")
			$(this).addClass("active")
			$(this).attr("state","active")
			$("#img_"+$(this).attr("item")).attr("src",handyPath+"img/active.png")
			localStorage[$(this).attr("item")] = 1
    		$(nodeHead+" link#handycss_"+$(this).attr("item")).attr("href",cssPath+$(this).attr("item")+".css");
    		return false;
		} else if($(this).attr("state") == "active"){
			$(this).removeClass("active")
			$(this).addClass("inactive")			
			$(this).attr("state","inactive")
			localStorage[$(this).attr("item")] = 0
			$("#img_"+$(this).attr("item")).attr("src",handyPath+"img/inactive.png")
			$(nodeHead+" link#handycss_"+$(this).attr("item")).attr("href",cssPath+"empty.css");
			return false;
		}
		
	})
	
}











